#include <stdlib.h>
#include <iostream>

#include "net_rbf.h"
#include "DataSupplier.h"

#define THRESHOLD 0.9

int main()
{
    ann::net_rbf rbfnet(4,2,1);

    rbfnet.Init(L"rbf_fish_init.info");
    rbfnet.LoadTRDataFromFile(L"cu_traindata.txt");
    rbfnet.Elect_C_KNN();
    rbfnet.TRStaticCenter();

    printf("finished training RBF net, start emulating checking.\n");

    DataSupplier::S()->InitFromFile(L"cu16_test.txt");
    //DataSupplier::S()->InitFromFile(L"cu17_test.txt");
    //DataSupplier::S()->InitFromFile(L"cu16_mid.txt");
    //DataSupplier::S()->InitFromFile(L"cu17_mid.txt");
    //DataSupplier::S()->InitFromFile(L"cd_test.txt");
    //DataSupplier::S()->InitFromFile(L"cr_test.txt");
    dVec testData;
    dVec ret;
    UINT idx;

    for( ; !DataSupplier::S()->IsEOF(); )
    {
        idx = DataSupplier::S()->PeekData(testData);
        if (idx == -1)
        {
            printf("error: failed to peek data\n");
            break;
        }

        rbfnet.Sim(testData, &ret);

        if (ret.size() != 1)
        {
            printf("error: Oooops, it seems something ungeiliable happened.\n");
            break;
        }

        if ( *ret.begin() > THRESHOLD )
        {
            printf(" find school abnormal at frame %d, time %fm,\n about %f minute past after poisioned, with output = %f.\n",
                    idx, DataSupplier::S()->QueryTime(), DataSupplier::S()->QueryPTime(), *ret.begin());
            break;
        }
    }

    if ( DataSupplier::S()->IsEOF() )
    {
        printf("It seems no abnormal found...\n");
    }


    system("pause");
    return 0;
}
